package question1.right;

import java.util.concurrent.ConcurrentLinkedQueue;

public class Worker implements Runnable {

    private int workerId;

    private ConcurrentLinkedQueue<Task> taskQueue;

    public Worker(int workerId, ConcurrentLinkedQueue<Task> taskQueue) {
        this.workerId = workerId;
        this.taskQueue = taskQueue;
    }

    @Override
    public void run() {
        while (!taskQueue.isEmpty()) {
            Task task = taskQueue.poll();
            task.doTask(this);
        }
    }


    public int getWorkerId() {
        return workerId;
    }

    public void setWorkerId(int workerId) {
        this.workerId = workerId;
    }

    public ConcurrentLinkedQueue<Task> getTaskQueue() {
        return taskQueue;
    }

    public void setTaskQueue(ConcurrentLinkedQueue<Task> taskQueue) {
        this.taskQueue = taskQueue;
    }

}
